<template>
	<view class="wrap">
		<scroll-view class="scroll-list" scroll-y="true">


			<view class="map-container">
				<MAP :list='list'></MAP>
			</view>

			<cover-view class="map-icon">
				<!-- 	<cover-view class="map-icon2">
					<cover-image class="item-img" src="@/static/aidex/msgNav.png"></cover-image>
					<cover-view class="item-text">消息</cover-view>
				</cover-view> -->
				<cover-view class="map-icon2" @click="showContent()">
					<cover-image class="item-img2" src="@/static/aidex/mapNav.png"></cover-image>
					<cover-view class="item-text2">图层</cover-view>
				</cover-view>
			</cover-view>


			<cover-view class="map-content" v-show="!this.showView">
				<cover-view v-for="(item, index) in list" :key="index" class="item-container"
					@click="change(item.id, item.organId)">
					<cover-image class="item-img" :src="item.icon" @click="change(item.id, item.organId)"></cover-image>
					<cover-view class="item-text" @click="change(item.id, item.organId)">{{item.name}}</cover-view>
				</cover-view>
			</cover-view>


			<!-- <view class="mapView">
			<view v-for="(item, index) in list" :key="index" :class="'item-' + index"
					@click="change(item.id, item.organId)">
					<image style="width:68rpx;height: 68rpx;object-fit: cover;" :src="item.icon" :size="34" @click="change(item.id, item.organId)"></image>
					<view style="	overflow: hidden;text-overflow: ellipsis;white-space: nowrap;" @click="change(item.id, item.organId)">{{item.name}}</view>
				</view>
			</view> -->
		</scroll-view>
	</view>
</template>

<script>
	import MAP from "@/components/map/mapView.vue"
	import wsIcon from "@/static/aidex/station.png"
	import maIcon from "@/static/aidex/mstation.png"
	export default {
		components: {
			MAP
		},
		data() {
			return {
				list: [],
				showView: false,
			}
		},
		created() {
			this.getData();
		},
		methods: {
			showContent() {
				this.showView = !this.showView
			},
			change(navId, organId) {
				uni.setStorageSync('navId', navId);
				uni.setStorageSync('organId', organId);
				uni.removeStorageSync('tabBar');
				uni.setStorageSync('tabBar', 1);
				uni.switchTab({
					url: '/pages/sys/index/index/index'
				});
			},
			async getData() {
				try {
					const res = await this.$u.api.searchEq({
						"algorithmProcessId": "getStationEq",
						"param": {
							"data": {
								user_uuid: uni.getStorageSync('uuid')
							}
						}
					});
					if (res && res.data && res.data.data && res.data.data.result) {
						if (res.data.data.result.length > 1) {
							this.list = res.data.data.result.map(item => {
								let icon = wsIcon;
								if (item.structure_name.toLowerCase().includes("污水厂")) {
									icon = wsIcon;
								} else {
									icon = maIcon;
								}
								return {
									id: item.id,
									name: item.structure_name,
									coordinate: item.coordinate,
									icon: icon,
									organ_uuid: ""
								};
							});
							const res2 = await this.$u.api.searchOne({
								"algorithmProcessId": "treeApp",
								"param": {
									"data": {
										user_id: uni.getStorageSync('uuid')
									}
								}
							});

							res2.data.data.result.children.forEach(item => {
								this.list.forEach(listItem => {
									if (listItem.name === item.title) {
										listItem.organId = item.organ_uuid;
									}
								});
							});
						} else {
							const navId = res.data.data.result[0].id;
							uni.removeStorageSync('navId');
							uni.setStorageSync('navId', navId);

							const res3 = await this.$u.api.searchOne({
								"algorithmProcessId": "treeApp",
								"param": {
									"data": {
										user_id: uni.getStorageSync('uuid')
									}
								}
							});

							if (res3) {
								const organId = res3.data.organ_id_value[0].organ_id;
								uni.removeStorageSync('organId');
								uni.setStorageSync('organId', organId);
							}

							uni.switchTab({
								url: '/pages/sys/index/index/index'
							});
							console.log("11122222222222222222222")
							uni.removeStorageSync('tabBar');
							uni.setStorageSync('tabBar', 0);
						}
					} else {
						this.$u.toast('查询异常,请重新登录');
					}
				} catch (error) {
					this.$u.toast('查询异常');
					console.error(error);
				}
			}


		}


	}
</script>

<style scoped>
	@import 'style/navigavtion.css';
</style>